<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input class="ipt1" type="text" />
    <select>
      <option>+</option>
      <option>-</option>
      <option>*</option>
      <option>/</option>
    </select>
    <input class="ipt2" type="text" />
    <button>点我运算</button>
    <input class="ipt3" type="text" />
  </body>
</html>
<script>
  var oIpt1 = document.querySelector(".ipt1");
  var oIpt2 = document.querySelector(".ipt2");
  var oIpt3 = document.querySelector(".ipt3");
  var oSelect = document.querySelector("select");
  var oBtn = document.querySelector("button");
  oBtn.onclick = function () {
    if (oIpt1.value.trim() == "") return alert("请输入内容");
    if (isNaN(oIpt1.value)) return alert("请输入数字");
    if (oSelect.value == "+") {
      oIpt3.value = oIpt1.value * 1 + oIpt2.value * 1;
    } else if (oSelect.value == "-") {
      oIpt3.value = oIpt1.value - oIpt2.value;
    } else if (oSelect.value == "*") {
      oIpt3.value = oIpt1.value * oIpt2.value;
    } else if (oSelect.value == "/") {
      oIpt3.value = oIpt1.value / oIpt2.value;
    }
  };
</script>
